package org.fei.ClassDiagram.drawing.Lines;

import org.fei.ClassDiagram.drawing.Lines.Line;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import org.fei.ClassDiagram.WindowComponents.Message;
import org.fei.ClassDiagram.drawing.Point;
import org.netbeans.modules.classfile.Variable;

/**
 *
 * @author Tomas
 */
public class AsotiationArrow extends Line {
    private Variable var;
    // premenna zavedena koli asociaciam, pocita kolko sa ich vztahuje k danej triede
    // na zaklade toho ich mozem vykreslovat pod sebou
    private int usages;
    private boolean isFirst;
    
    // na zobrazenie asociacii
    private static boolean showAsociationName = true;
    public AsotiationArrow(Point start, Point end, Variable var, int usages, boolean isFirst) {
        super(start, end);
        this.var = var;
        this.usages = usages;
        this.isFirst = isFirst;
    }

    @Override
    public void draw(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
        // The rendering hints are used to make the drawing smooth.
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);       
        g2d.setRenderingHints(rh);
        
        if (AsotiationArrow.showAsociationName) {
            String name = new String();
            if (var.isPublic())
                name += "+ ";
            if (var.isPrivate())
                name += "- ";
            if (var.isProtected())
                name += "# ";
            name += var.getName();
            name += " {" + var.getClassFile().getName().toString() + "}";
            Font f = new Font(Font.SANS_SERIF, Font.PLAIN, fontSize);
            g2d.setFont(f);
            FontMetrics fm = g.getFontMetrics();
            g2d.drawString(name, end.getX()+ 3, end.getY() + 3 + (fm.getHeight()*this.usages-1));
        }
        
        if (isFirst)
            g2d.drawLine(start.getX(), start.getY(), end.getX(), end.getY());
    }

    public static void setShowAsociationName(boolean showAsociationName) {
        AsotiationArrow.showAsociationName = showAsociationName;
    }
}